import java.util.ArrayList;
import java.util.List;


public class MyArrList extends ArrayList<AndroidFile>
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ArrayList<AndroidFile> sort(ArrayList<AndroidFile> list)
	{
		if (list.size()==1)
			return list;
		int start=0;
		int middle=list.size()/2;
		int end=list.size();
		return mergeSort(list.subList(start, middle),list.subList(middle, end));
	}

	public ArrayList<AndroidFile> mergeSort(List<AndroidFile> left, List<AndroidFile> right)
	{
		int leftSize=left.size();
		int rightSize=right.size();
		if (leftSize>1)
		{
			int start=0;
			int middle=leftSize/2;
			int end=leftSize;
			left=mergeSort(left.subList(start, middle),left.subList(middle, end));
		}
		if (rightSize>1)
		{
			int start=0;
			int middle=(Math.round(rightSize/2));
			int end=rightSize;
			right=mergeSort(right.subList(start, middle),right.subList(middle, end));
		}
		ArrayList<AndroidFile> ret=new ArrayList<AndroidFile>();
		int i=0,j=0;
		while (i<leftSize && j<rightSize)
		{
			if (((AndroidFile)left.get(i)).getName().compareToIgnoreCase(((AndroidFile)right.get(j)).getName())<0)
			{
				ret.add(left.get(i));
				i++;
			}
			else
			{
				ret.add((AndroidFile)right.get(j));
				j++;
			}
		}
		while (i<leftSize)
		{
			ret.add(left.get(i));
			i++;
		}
		while (j<rightSize)
		{
			ret.add(right.get(j));
			j++;
		}
		return ret;
	}

}
